using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DoAn_LyThuyet.HeThongXuLy;

namespace DoAn_LyThuyet.HeThongLuuTru
{
    class PhanBoTaiSanDAO
    {
        static public DataTable SelectTaiSanPhanBo()
        {
            string sql = "select MaPhanBo, MaPhong, MaTaiSan, CanBoGiao, CanBoNhan, SoBienBan, NgayPhanBo from PhanBoTaiSan";

            DataTable dt = DataAccess.GetTable(sql);
            return dt;
        }
        static public DataTable SelectPhong()
        {
            string sql = "select * from Phong";

            DataTable dt = DataAccess.GetTable(sql);
            return dt;
        }
        static public DataTable SelectTaiSanAll_TheoPhong(String maphong)
        {
            string sql = "select * from PhanBoTaiSan Where  MaPhong = '" + maphong + "'";

            DataTable dt = DataAccess.GetTable(sql);
            return dt;
        }
       
        public static bool Insertpb(PhanBoTaiSanDTO pb)
        {
            try
            {
                //string strngay = pb.NgayPhanBo.Day + "/" + pb.NgayPhanBo.Month + "/" + pb.NgayPhanBo.Year;
                string strngay = pb.NgayPhanBo.ToShortDateString();
                string sql = "insert into PhanBoTaiSan(MaPhong,MaTaiSan,CanBoGiao,CanBoNhan, SoBienBan, NgayPhanBo) values('" +
                    pb.MaPhong + "','" + pb.MaTaiSan + "','" + pb.CanBoGiao + "','" + pb.CanBoNhan +
                    "', " + pb.SoBienBan + ",'" + strngay + "')";
                DataAccess.GetTable(sql);
                return true;
            }
            
            catch (Exception ex)
            {
                return false;
            }

        }
        static public PhanBoTaiSanDTO SelectTSPB(string name)
        {
            string sql = "select * from PhanBoTaiSan where MaTaiSan = '" + name + "'";
            DataTable dt = DataAccess.GetTable(sql);
            if (dt.Rows.Count == 0)
            {
                return null;
            }
            else
            {
                PhanBoTaiSanDTO ts = new PhanBoTaiSanDTO();
                ts.MaPhong = dt.Rows[0].ItemArray[0].ToString();
                ts.MaTaiSan = dt.Rows[0].ItemArray[1].ToString();
                ts.CanBoGiao = dt.Rows[0].ItemArray[2].ToString();
                ts.CanBoNhan = dt.Rows[0].ItemArray[3].ToString();
                // ts.SoBienBan = dt.Rows[0].ItemArray[4].GetType ();

                return ts;
            }
        }
        public static bool DeletePb(int pb)
        {
            
            try
            {
                
                string sql = "Delete from PhanBoTaiSan where MaPhanBo = " + pb + " ";
                DataAccess.GetTable(sql);
                return true;
            }

            catch (Exception ex)
            {
                return false;
            }

        }
       
    }
}
